package com.lik.springcloud.service;

import com.lik.springcloud.entities.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Shadow
 */

// 这里需要@Component
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory<DeptClientService> {

    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public Dept get(long id) {
                return null;
            }

            @Override
            public List<Dept> list() {
                Dept no_this_database_in_mySQL = new Dept().setDname("没有没有对应的信息,Consumer客户端提供的降级信息,此刻服务Provider已经关闭")
                        .setDb_source("no this database in MySQL");
                ArrayList<Dept> depts = new ArrayList<>();
                depts.add(no_this_database_in_mySQL);
                return depts;
            }

            @Override
            public boolean add(Dept dept) {
                return false;
            }
        };
    }
}
